<?php use_helper ('Form','DateForm','Object') ?>
<?php //decorate_with(false) ?>
<?php use_javascript('jquery-1.3.2.min.js') ?>

<?php if(!$flag):?>
<script language="javascript">
var stations = <?php echo json_encode($Station); ?>;
var buildings = <?php echo json_encode($Building); ?>;

var result = {};

function populateArray(rVal)
{
	var plen = jQuery('#building_id')[0].length
	for (var i=0; i<plen; i++)
	{
		jQuery('#building_id')[0][0] = null;
	}
	var count=0;
	jQuery.each(buildings, function(i, val)
	{
	if (val[0] == rVal)
		{
		jQuery('#building_id')[0][count++] = new Option(val[1], i);
		}
	});
} // END populateArray

jQuery(function(){
	populateArray(jQuery("#station_id").val());
	jQuery("#station_id").change(function(){
		populateArray(jQuery("#station_id").val());
	});
}
); //END

</script>

<?php echo form_tag('Billing/addJcoBill') ?>
<table class="form" width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr height="30">
  	<td colspan="4" valign="top"> <h3>Please Select Station / Building to make bill for.</h3>
  </tr>
 

  <tr height="30">
		<td width="14%">Station:</td>
		<td width="86%"> <?php echo object_select_tag('', '', array ( 'name'=>'station_id', 'id'=>'station_id', 'related_class' => 'Station' , 'peer_method' => 'GetStation' , 'onchange'=>'populateArray()'));?></td>
  </tr>


  <tr height="30">
		<td width="14%">Building:</td>
		<td width="86%"> <?php echo object_select_tag('', '', array ( 'name'=>'building_id', 'id'=>'building_id', 'related_class' => 'Building' , 'peer_method' => 'GetBuilding'));?></td>
  </tr>
	
	<tr height="50">
		<td>&nbsp;</td>
		<td colspan="2" valign="top">
		<table width="100%" align="left" border="0" class="form">
			<tr>
				<td width="2%"><?php echo submit_tag(' ', array('class' => 'btn_submit', 'style'=>'border:none')); ?> </td>
				<td width="96%">&nbsp;</td>
			</tr>
    	</table>
		</td>
  </tr>
  
  </table>
  </form>
<?php endif ;?>
  
<?php if($flag):?>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tbody>
		<tr>
			<td colspan="2" nowrap="nowrap">
				<table width="100%" border="0" cellspacing="0" cellpadding="0" class="school_hdng">
					<tr>
					<td><h3>Utility bill for: <span><?php if ($occupant){echo $occupant->getRank(). ' '.$occupant->getName();} ?></span></h3></td>
					<td align="right"><h3>&nbsp;</h3></td>
					</tr>
					
				</table>
			</td>
		</tr>
		
		<tr>
			<td height="20" colspan="2">&nbsp;</td>
		</tr>
	</tbody>
</table>

<?php echo form_tag('Billing/makeJcoBill') ?>
<?php if (count($occupant)){echo input_hidden_tag('occupant_id', $occupant->getId());} ?>

<table width="100%" border="0" cellspacing="0" cellpadding="0" class="datagrid">

<tr style="height:30px;">
    <td><strong>Building No. :</strong> <?php echo $building->getBuildingNo() ;?></td>
    <td><strong>Consumer No. :</strong> <?php echo $building->getConsumerNo();?></td>
    <td><strong>Meter No. :</strong> <?php echo $building->getMeterNo();?></td>
    <td><strong>Station:</strong> <?php echo $building->getStation();?></td>
</tr> 

	<?php if (count($occupant)): ?>
    <tr style="height:30px;">
        <td><strong>Army No. :</strong> <?php echo $occupant->getArmyNo() ;?></td>
        <td><strong>Rank / Name:</strong> <?php echo $occupant->getRank(). ' ' .$occupant->getName();?></td>
        <td><strong>Unit / Formation :</strong> <?php echo $occupant->getUnit();?></td>
        <td></td>
    </tr>
    <?php else:?>
    <tr style="height:30px;">
        <td colspan="4"><h3 style="color:red;">The Building is "Not Occpupied. Please assign occupant to the building.</h3></td>
    </tr>
    <?php endif;?>              

<tr>
	<td class="last">&nbsp;</td>
</tr>	
 
</table>

<?php if (count($occupant)): ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="form">

<tr style="height:30px;">
    <td width="15%"><strong>Previous Reading:</strong></td>
    <td width="85%">
	<?php if($previous_bill):?>
		<?php echo $previous_bill->getPresentReading(); ?> Units
		<?php echo input_hidden_tag('previous_reading',$previous_bill->getPresentReading());?>
	<?php else:?>
		<?php echo input_tag('previous_reading', 0, 'size=20');?>
	<?php endif;?>
    </td>
</tr>



<tr style="height:30px;">
    <td width="15%"><strong>Billing Month/Year:<span class="error"> *</span>(Y-m-d)</strong></td>
    <td width="85%"><?php echo select_month_tag('billing_month', date('m')-1, 'use_short_month=true'); ?><?php echo select_year_tag('billing_year', date('Y'), 'year_end=2020') ?>
    <script type="text/javascript">
	var billing_date = new LiveValidation('billing_date', { validMessage: "<?php echo Constant::VALIDATION_SUCCESS;?>", wait:500});
	billing_date.add( Validate.Presence,{ failureMessage: "<?php echo Constant::VALIDATION_REQUIRED_FIELD;?>"});
	</script>
    </td>
</tr>


<tr style="height:30px;">
    <td><strong>Present Reading:<span class="error"> *</span></strong></td>
    <td><?php echo input_tag('present_reading', '', 'size=30')?>
    <script type="text/javascript">
	var present_reading = new LiveValidation('present_reading', { validMessage: "<?php echo Constant::VALIDATION_SUCCESS;?>", wait:500});
	present_reading.add( Validate.Presence,{ failureMessage: "<?php echo Constant::VALIDATION_REQUIRED_FIELD;?>"});
	present_reading.add( Validate.Numericality, { failureMessage: "<?php echo 'Digits only'  ?>"} );
	</script>
    </td>
</tr> 

<tr style="height:30px;">
    <td><strong>Free Allowed Units:<span class="error"> *</span></strong></td>
    <td><?php echo radiobutton_tag('free[]', Constant::SOLDIER_FREE_UNITS_WINTER, true, array('class'=>'checkbox')) ?>Winter &nbsp;&nbsp;&nbsp;
	<?php echo radiobutton_tag('free[]', Constant::SOLDIER_FREE_UNITS_SUMMER, false, array('class'=>'checkbox')) ?>Summer
    </td>
</tr> 

<tr style="height:30px;">
    <td><strong>Gas Charges:</strong></td>
    <td><?php echo input_tag('gas_charges', '', 'size=30')?>
    <script type="text/javascript">
	var gas_charges = new LiveValidation('gas_charges', { validMessage: "<?php echo Constant::VALIDATION_SUCCESS;?>", wait:500});
	gas_charges.add( Validate.Numericality, { failureMessage: "<?php echo 'Digits only'  ?>"} );
	</script>
    </td>
</tr> 

<tr style="height:30px;">
    <td><strong>Misc Charges:</strong></td>
    <td><?php echo input_tag('misc_charges', '', 'size=30')?>
    <script type="text/javascript">
	var misc_charges = new LiveValidation('misc_charges', { validMessage: "<?php echo Constant::VALIDATION_SUCCESS;?>", wait:500});
	misc_charges.add( Validate.Numericality, { failureMessage: "<?php echo 'Digits only'  ?>"} );
	</script>
    </td>
</tr> 


<tr style="height:30px;">
    <td><strong>Furniture Charges:</strong></td>
    <td><?php echo input_tag('furniture_charges', '', 'size=30')?>
    <script type="text/javascript">
	var furniture_charges = new LiveValidation('furniture_charges', { validMessage: "<?php echo Constant::VALIDATION_SUCCESS;?>", wait:500});
	furniture_charges.add( Validate.Numericality, { failureMessage: "<?php echo 'Digits only'  ?>"} );
	</script>
    </td>
</tr>

<tr style="height:30px;">
    <td><strong>Direct AC Charges:</strong></td>
    <td>No. of Split AC: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <?php echo input_tag('split_value','','size=3')?>
    <script type="text/javascript">
	var split_value = new LiveValidation('split_value', { validMessage: "<?php echo Constant::VALIDATION_SUCCESS;?>", wait:500});
	split_value.add( Validate.Numericality, { failureMessage: "<?php echo 'Digits only'  ?>"} );
	</script>
    </td>
</tr>

<tr style="height:30px;">
    <td>&nbsp;</td>
    <td>No. of Window AC: &nbsp;<?php echo input_tag('window_value','','size=3')?>
    <script type="text/javascript">
	var window_value = new LiveValidation('window_value', { validMessage: "<?php echo Constant::VALIDATION_SUCCESS;?>", wait:500});
	window_value.add( Validate.Numericality, { failureMessage: "<?php echo 'Digits only'  ?>"} );
	</script>
    </td>
</tr>

<tr style="height:30px;">
    <td>&nbsp;</td>
    <td>&nbsp;</td>
</tr>               

<tr>
	<td>&nbsp;</td>
    <td colspan="3"><table width="100%"  align="left" border="0" class="form">
      <tr>
        <td width="4%"><?php echo submit_tag(' ', array('class'=>'btn_submit', 'style'=>'border:none')); ?> </td>
        <td width="96%"><?php echo link_to(' ', (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : 'Home/index', array('class' => 'btn_cancel'));
 ?></td>
      </tr>
    </table></td>
  </tr>
<tr>
	<td class="last">&nbsp;</td>
</tr>	
 
</table>
  </form>
<?php endif ?>  
<?php endif ?>